package com.hpu.parser;

import com.hpu.bean.Borrow;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Liu ZhuangFei on 2018/3/24.
 */

public class BookBorrowParser {

    public static List<Borrow> parse(String json){
        List<Borrow> borrows=new ArrayList<>();
        try {
            JSONArray array=new JSONArray(json);
            for(int i=0;i<array.length()-2;i+=3){
                String stack=array.getString(i);
                String room=array.getString(i+1);
                String status=array.getString(i+2);
                borrows.add(new Borrow(stack,room,status));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return borrows;
    }
}
